package org.blogsomy.model.dao;

import java.util.List;

import org.blogsomy.model.entities.User;

public class UserDao extends HibernateDao<User> {

	public UserDao() {
		super(User.class);
	}

	@SuppressWarnings("unchecked")
	public User find(String username, String password) {
		String query = "from User u where u.name = :name and u.password = :password";
		List<User> l = (List<User>) getHibernateTemplate().findByNamedParam(
				query, 
				new String[] { "name", "password" },
				new String[] { username, password });
		return l.size() > 0 ? l.get(0) : null;
	}
	
	@SuppressWarnings("unchecked")
	public User find(String username) {
		String query = "from User u where u.name = :name";
		List<User> l = (List<User>) getHibernateTemplate().findByNamedParam(
				query, "name", username);
		return l.size() > 0 ? l.get(0) : null;
	}
}
